﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cricket.LinqData;
using Cricket.LinqModel;
using System.Web.Services;

public partial class Dashboard : System.Web.UI.Page
{
    #region Variable Declaration
    IDataRepository _dataObject = new DataRepository();
    MatchSchedule matchSchedule;    
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            HttpCookie cookie = Request.Cookies["Client"];
            if (cookie == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                bindMatches();
               
            }
        }
    }

    private void bindMatches()
    {
        matchSchedule = new MatchSchedule(_dataObject);
        List<GetUpComingMatchesResult> lstMatches = new List<GetUpComingMatchesResult>();
        lstMatches = matchSchedule.GetUpComingMatches();
        if (lstMatches.Count > 0)
        {
            rptMatch.DataSource = lstMatches;
            rptMatch.DataBind();
        }
        else
        {
            rptMatch.DataSource = null;
            rptMatch.DataBind();
        }
    }

    [WebMethod]
    public static int Logout(int cId)
    {
        var response = HttpContext.Current.Request;
        HttpCookie cookie = response.Cookies["Client"];
        int clientId = 0;
        
        clientId = Convert.ToInt32(cookie["ClientId"]);

        
        IDataRepository _dataObject1 = new DataRepository();
    
        Client client = new Client(_dataObject1);
        List<Client> lst = new List<Client>();
        client.Id = Convert.ToInt32(clientId);
        client.GetClientById();
        if (client.IsLogin == false)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }

    [WebMethod]
    public static int LogoutUser(int cId)
    {
        var response = HttpContext.Current.Request;
        HttpCookie cookie = response.Cookies["Client"];
        int clientId = 0;

        clientId = Convert.ToInt32(cookie["ClientId"]);


        IDataRepository _dataObject1 = new DataRepository();

        Client client = new Client(_dataObject1);
        List<Client> lst = new List<Client>();
        client.Id = Convert.ToInt32(clientId);
        client.GetClientById();
        if (client.IsLogin == false)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    
}